﻿using DataServer.ApplicationLib.Services;
using DataServer.CommonLib.Models.ConfigData;
using Microsoft.AspNetCore.Mvc;

namespace Config.WebApi.Controllers
{
    [Route("api/v1/configDatas")]
    [ApiController]
    public class ConfigDataController : ControllerBase
    {
        private readonly IConfigDataService _configDataService;

        public ConfigDataController(IConfigDataService configDataService)
        {
            _configDataService = configDataService;
        }

        [HttpGet]
        public async Task<IActionResult> Get([FromQuery] ConfigDataSearchRequestDto model)
        {
            if (model.Page > 0 || model.Limit > 0)
            {
                var data = await _configDataService.QueryConfigDatasByPageAsync(model);
                return Ok(data);
            }
            else
            {
                var data = await _configDataService.QueryConfigDatasAsync(model);
                return Ok(data);
            }
        }

        [HttpPost]
        public async Task<IActionResult> Create([FromBody] IDictionary<string, object> model)
        {
            var data = await _configDataService.CreateAsync(model);
            return Ok(data);
        }
    }
}